from owlready2 import *

onto = get_ontology("http://test.org/drug.owl")

with onto:
    class Drug(Thing): pass
    class number_of_tablets(Drug >> int, FunctionalProperty): pass
    class price(Drug >> float, FunctionalProperty): pass
    class price_per_tablet(Drug >> float, FunctionalProperty): pass
    rule = Imp()
    rule.set_as_rule("""Drug(?d), price(?d, ?p), number_of_tablets(?d, ?n), divide(?r, ?p, ?n) -> price_per_tablet(?d, ?r)""")



    print('1. creating SWRL rules')
    drug = Drug(number_of_tablets = 10, price = 25.0)
    sync_reasoner_pellet(infer_property_values = True, infer_data_property_values = True)
    print('\t', drug.price_per_tablet)



    print('2. displaying rules')
    print('\t', str(rule))



    print('3. modifying rules manually')
    print('\trule.body: ', rule.body)
    print('\trule.head: ', rule.head)
    print('\trole.body[0]: ', rule.body[0])
    print('\trule.body[0].class_predicate: ', rule.body[0].class_predicate)
    print('\trule.body[0].arguments: ', rule.body[0].arguments)

